package io.github.kouleen.manager.command;

import io.github.kouleen.manager.service.ManagerXConnectService;

import io.github.kouleen.minecraft.core.lang.annotation.MinecraftPluginCommand;
import org.bukkit.command.*;
import org.bukkit.entity.Player;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author zhangqing
 * @since 2025/1/25 21:07
 */
@MinecraftPluginCommand({"managerx","manx"})
public class ChickenCommandService implements TabExecutor {

    @Override
    public boolean onCommand(CommandSender commandSender, Command command, String label, String[] args) {
        Map<UUID, String> players = ManagerXConnectService.getPlayers();
        if (args.length == 0) {
            commandSender.sendMessage("§2§l====§8§l【§a§l     ManagerX    §8§l】§2§l====");
            commandSender.sendMessage("§2§l====§8§l【§a§l QQ群：645375329 §8§l】§2§l====");
            commandSender.sendMessage("§7§l/managerx <off> §6禁止骚扰，关闭毒鸡汤");
            commandSender.sendMessage("§7§l/managerx <on>  §6我想调情，打开消息");
            return true;
        }
        if (args.length == 1) {
            String commandArg = args[0];
            if (commandSender instanceof Player) {
                Player player = (Player) commandSender;
                UUID uniqueId = player.getUniqueId();
                if (commandArg.equalsIgnoreCase("off")) {
                    if (!players.containsKey(uniqueId)) {
                        players.put(uniqueId, player.getName());
                        commandSender.sendMessage("§2设置成功。毒鸡汤已关闭");
                        return true;
                    }
                }
                if (commandArg.equalsIgnoreCase("on")) {
                    if (players.containsKey(uniqueId)) {
                        players.remove(uniqueId);
                        commandSender.sendMessage("§2设置成功。毒鸡汤已开启");
                        return true;
                    }
                }
            }
        }
        return false;
    }

    @Override
    public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
        if (strings.length == 1) {
            if (commandSender instanceof Player) {
                return Arrays.asList("on", "off").parallelStream().filter(cmd -> cmd.contains(strings[0].toLowerCase())).collect(Collectors.toList());
            }
        }
        return Collections.emptyList();
    }
}
